<table style="width: 98%;">
    <tr>
        <td class="theader">方案名称</td>
        <td>
            <input id="name" name="name" allowinput="true" shownullitem="false" class="mini-textbox" style="width:100%" />
        </td>
    </tr>
    <tr>
        <td class="theader">年份</td>
        <td>
            <input id="year" name="year" allowinput="true" shownullitem="false" class="mini-textbox" style="width: 100%;" />
        </td>
    </tr>
    <tr>
        <td class="theader">月份</td>
        <td>
            <input id="month" name="month" allowinput="true" shownullitem="false" class="mini-textbox" style="width: 100%;" />
        </td>
    </tr>

    <tr>
        <td class="theader">生效日期</td>
        <td>
            <input id="effect_date" name="effect_date" allowinput="true" shownullitem="false" class="mini-datepicker" style="width: 100%;" />
        </td>
    </tr>
    <tr>
        <td class="theader">失效日期</td>
        <td>
            <input id="expire_date" name="expire_date" allowinput="true" shownullitem="false" class="mini-datepicker" style="width: 100%;" />
        </td>
    </tr>
    <tr>
        <td class="theader">说明</td>
        <td>
            <input id="description" name="description" allowinput="true" shownullitem="false" class="mini-textarea" style="width: 100%;" />
        </td>
    </tr>
</table>

<div class="mini-fit">
    <div title="SKU码">
        <div style="width:100%; height: 200px">
            <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                            <a class="mini-button" iconcls="icon-add" onclick="fnSelectDept()">选择部门</a>
                            <a class="mini-button" iconcls="icon-remove" onclick="fnOpRemove()">删除</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div id="datagrid1" class="mini-datagrid" pagesize="20" allowresize="true" allowscroll="true" allowcelledit="true" allowcellselect="true" multiselect="true" showpager="flase" url=""
                 editnextonenterkey="true" editnextrowcell="true" idfield="id" multiselect="true" pagesize="100">
                <div property="columns">
                    <div field="dept_name" width="50" showloading="false" headeralign="center" allowsort="true">部门名称<input property="editor" class="mini-textbox" style="width:100%;" /></div>
                    <div field="sort" width="50" showloading="false" headeralign="center" allowsort="true">排序<input property="editor" class="mini-textbox" style="width:100%;" /></div>
                    <div field="description" width="150" headeralign="center" allowsort="true">说明<input property="editor" class="mini-textbox" style="width:100%;" /></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //添加grid行 e:grid的id
    function fnOpAdd(obj) {
        var grid = mini.get("datagrid1");
        var newRow = { id: newguid(), "solution_id": instance.id };
        if (obj) {
            newRow.dept_name = obj.name;
            newRow.root_dept_id = obj.id;
        }
        grid.addRow(newRow, 0);
    }


    //删除grid行 e:grid的id
    function fnOpRemove() {
        var grid = mini.get("datagrid1");
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            grid.removeRows(rows, true);
            $.each(rows, function (i) {
                //edit.common.js的通用方法
                fnFormRemove("t_hr_performance_assessment_setting", "id", rows[i].id);
            });
        }
    }

    ///绑定下拉列表
    $(document).ready(function () {
        fnDataGridDataBing("datagrid1", "/extendpage/data/jsondata.aspx?entity=t_hr_performance_assessment_setting&order=sort&condition=solution_id='" + instance.id + "'")
    });


    function fnCustomSave() {
        var form = new mini.Form("#form1");
        form.validate();
        if (!form.isValid()) return;
        var form_data = form.getData();
        fnClone(form_data, instance);
        if (typeof (instance) != "undefined" && instance != null) {
            var msg = mini.loading("数据保存中，请稍后......", "系统消息提醒");
            var json = mini.encode(instance);   //序列化成JSON
            var grid = mini.get("datagrid1");
            var data = grid.getChanges();
            var json2 = mini.encode(data);
            json = json + "[@@@]" + json2;
            var _rData = mini.encode(_removeData);
            $.ajax({
                url: "/extendpage/action/datasave.aspx?entity=t_hr_performance_assessment_solution:t_hr_performance_assessment_setting&flag=1&action=mutibatchsave",
                type: "post",
                data: { data: json, removeData: _rData },
                cache: false,
                success: function (text) {
                    if (text == 1) {
                        alert("数据保存成功!")
                        fnClose();
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
            mini.hideMessageBox(msg);
        }
    }


    var fnSelectDept = function () {
        //var row = fnGetSelectedRow();
        mini.open({
            url: "/ExtendPage/template/dialogpage/TreeDeptWindow.html?entity=" + const_EditEntity + "&functionid=" + const_functionId + "&action=importdata&id=",
            title: "上传文件", width: 450, height: 300,
            onload: function () {
                var iframe = this.getIFrameEl();
                //var data = { action: "new" };
                //var data = iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.GetData();
                    CallBack(data);
                }
            }
        });
    }

    var CallBack = function (data) {
        //alert(data);
        $.each(data, function (index, e) {
            fnOpAdd(e);
        })
    }



</script>